<?php
include('../common/_const.php');
include('../common/common.php');
include('../common/checksession.php');
checksession("../index.php");
include('../../inc/conn.php');

//function display_children($parent,$space){
//	$db=db_connect();//数据库连
//	$sql="SELECT `typename`,`id` FROM  `ten_arctype` WHERE `topid`='".$parent."'";
//	$rs = $db->query($sql); 
//	while($row = $rs->fetch_assoc()){
//	echo str_repeat('++',$space).$row['typename']."<br/>"; 
//	display_children($row['id'],$space+1);
//	}	
//	}
//	display_children(0,1);

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $sys_title['catalog']; ?></title>
<link href="../images/css1/css.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../images/m.js"></script>
<script type="text/javascript">
//// 收缩展开效果
//$(document).ready(function(){
//   $(".type_top .scbtn").toggle(function(){
//     $(this).parent().next(".type_son").animate({height: 'toggle', opacity: 'toggle'}, "slow");
//   },function(){
//		 $(this).parent().next(".type_son").animate({height: 'toggle', opacity: 'toggle'}, "slow");
//   });
//});
</script>
<script type="text/javascript">
function submitform(){
	document.getElementById('rankform').submit();
}
function del_ckeck(o){
	
	if(window.confirm("栏目下的文章也将一并删除且不可恢复,确认删除!")){
	 window.location.href="../action/ac_del_catalog.php?catid="+o;
	}

}
</script>
</head>

<body>
<form  name="rankform" id="rankform" method="post" action="../action/ac_changerank.php">
<table class="table" cellspacing="1" cellpadding="2" width="99%" align="center" 
border="0">
  <tbody>
    <tr>
      <th class="bg_tr" align="left" height="25"><?php echo $sys_title['catalog']; ?></th>
      <th class="bg_tr" align="right" height="25">
      <a href="catalog_add.php" class="typebt">添加栏目</a>
      <a href="#" class="typebt" onclick="javascript:submitform()" >更新排序</a>
     
      </th>
    </tr>
    
    <tr>
      <td height="23" colspan="2" bgcolor="#fefefe">
		<ul class="typelist">
        
        <?php 
		//显示栏目递归调用
		function display_children($parent,$class,$space){
			$ishidden=array(0=>"显示",1=>"<font color='red'>隐藏</font>");
			$db=db_connect();//数据库连
			
			$sql="SELECT `typename`,`id`,`ishidden`,`sortrank` FROM  `".PRETABLE."arctype` WHERE `topid`='".$parent."' ORDER BY `sortrank` ASC";
			$rs = $db->query($sql); 
			while($row = $rs->fetch_assoc()){
				$num_sql="SELECT `id` FROM `".PRETABLE."arcmain` WHERE `typeid`='".$row['id']."' AND `isdel`='0'";
				$num_rs=$db->query($num_sql);
				$count=$num_rs->num_rows;
			echo "<li class=\"".$class."\">
            <div class=\"space_s\" style=\"width:".$space."px;\"></div>
            	<div class=\"scbtn\"></div>
                <div class=\"type_title\">
                <span><a href=\"content_list.php?catid=".$row['id']."&pages=1\">".$row['typename']."</a></span>
                 <span>ID:".$row['id']."</span>
                  <span>(文档:".$count.")</span>
                </div>
                <div class=\"rank\"><input type=\"text\"  maxlength=\"3\" name=\"rank_".$row['id']."\" value=\"".$row['sortrank']."\" /></div>
                <div class=\"type_m\">
					<span>状态：".$ishidden[$row['ishidden']]."</span>
					<span><a href=\"catalog_edit.php?catid=".$row['id']."\">编辑</a></span>
					<span><a href=\"#\" onclick=\"del_ckeck(".$row['id'].")\" >删除</a></span>
                </div>
                
            </li>"; 
			display_children($row['id'],"type_son",$space+10);
			}
			
			$rs->close();
			$db->close();
		}
		display_children(0,"type_top",3);//调用递归函数
		
		?>           
        </ul>

      </td>
    </tr>
    
      
  
     <tr>
      <td class="td_bg" width="17%" height="23"></td>
      <td class="td_bg" width="83%">
      <input type="hidden" name="gurl" value="<?php echo GetCurUrl(); ?>" />
      </td>
    </tr>
  </tbody>
</table>
</form>
</body>
</html>